typedef int             bool;
typedef unsigned int    u32int;
typedef int             s32int;
typedef unsigned short  u16int;
typedef short           s16int;
typedef unsigned char   u8int;
typedef char            s8int;

typedef struct {
    u16int limit_low;
    u16int base_low;
    u8int base_middle;
    u8int access;
    u8int granularity;
    u8int base_high;
} __attribute__((packed)) gdt_entry;

typedef struct {
    u16int base_low;
    u16int selector;
    u8int unused;
    u8int flags;
    u16int base_high;
} __attribute__((packed)) idt_entry;

typedef struct {
    u16int limit;
    u32int base;
} __attribute__((packed)) gdt_pointer;

typedef struct {
    u16int limit;
    u32int base;
} __attribute__((packed)) idt_pointer;

typedef struct {
    u8int foreground;
    u8int background;
} output_colors;

typedef struct{
    void (*start)(void);
    void (*end)(void);
    u16int cs;
} int_routine_desc;

typedef struct {
    u32int eax;
    u32int ebx;
    u32int ecx;
    u32int edx;
} general_registers;

typedef struct {
    /* Original DS */
    u32int ds;
    /* From PUSHA */
    u32int dsi;
    u32int esi;
    u32int ebp;
    u32int esp;
    u32int ebx;
    u32int edx;
    u32int ecx;
    u32int eax;
    /* From Helper Routine */
    u32int interrupt;
    /* Sometimes from Interrupt sometimes Helper, always popped */
    u32int error_code;
    /* From Interrupt (popped by iret)*/
    u32int eip;
    u32int cs;
    u32int eflags;
    /* From Interrupt (popped by iret) ** ONLY IF FROM/TO VM86 TASK **/
    u32int v86_sp;
    u32int v86_ss;
    u32int v86_es;
    u32int v86_ds;
    u32int v86_fs;
    u32int v86_gs;
} isr_stack;

typedef struct {
    u32int eip;
    u32int cs;
    u32int eflags;
    u32int esp;
    u32int ss;
    u32int es;
    u32int ds;
    u32int fs;
    u32int gs;
} iret_image;

typedef struct {
  int width, height, depth;
  int address;
  int scanLineSize;
} video_descriptor;

typedef struct
{
   u32int prev_tss;   // The previous TSS - if we used hardware task switching this would form a linked list.
   u32int esp0;       // The stack pointer to load when we change to kernel mode.
   u32int ss0;        // The stack segment to load when we change to kernel mode.
   u32int esp1;       // Unused...
   u32int ss1;
   u32int esp2;
   u32int ss2;
   u32int cr3;
   u32int eip;
   u32int eflags;
   u32int eax;
   u32int ecx;
   u32int edx;
   u32int ebx;
   u32int esp;
   u32int ebp;
   u32int esi;
   u32int edi;
   u32int es;         // The value to load into ES when we change to kernel mode.
   u32int cs;         // The value to load into CS when we change to kernel mode.
   u32int ss;         // The value to load into SS when we change to kernel mode.
   u32int ds;         // The value to load into DS when we change to kernel mode.
   u32int fs;         // The value to load into FS when we change to kernel mode.
   u32int gs;         // The value to load into GS when we change to kernel mode.
   u32int ldt;        // Unused...
   u16int trap;
   u16int iomap_base;
} __attribute__((packed)) tss_entry;

typedef struct aout_symbol_table {
	unsigned long tabsize;
	unsigned long strsize;
	unsigned long addr;
	unsigned long reserved;
} __attribute__((packed)) aout_symbol_table;

typedef struct elf_section_header_table {
	unsigned long num;
	unsigned long size;
	unsigned long addr;
	unsigned long shndx;
} __attribute__((packed)) elf_section_header_table;
	 
typedef struct multiboot_info {
	unsigned long flags;
	unsigned long mem_lower;
	unsigned long mem_upper;
	unsigned long boot_device;
	unsigned long cmdline;
	unsigned long mods_count;
	unsigned long mods_addr;
	union
	{
	 aout_symbol_table aout_sym;
	 elf_section_header_table elf_sec;
	} u;
	unsigned long mmap_length;
	unsigned long mmap_addr;
} __attribute__((packed)) multiboot_info;

typedef struct multiboot_memory_map {
	unsigned int size;
	unsigned int base_addr_low,base_addr_high;
	unsigned int length_low,length_high;
	unsigned int type;
} __attribute__((packed)) multiboot_memory_map;

typedef struct module {
	unsigned int mod_start;
	unsigned int mod_end;
	unsigned int string;
	unsigned int reserved;
} __attribute__((packed)) module;


typedef void (*keyboard_handler)(int, u8int, bool);
typedef void (*timer_handler)(u32int);
typedef void (*isr_handler)(isr_stack);
